var before_value='';
$(function() {
	before_value=$('#system_code').val();
	reloadTree($('#role_id').val(), before_value);

	// 点击完成按钮
	$('#saveRoleButt').click(function() {
		saveRolePermission($('#system_code').val(), true);
	});
});

function onChangeSystem(obj, e) {
	var s = $('#system_code');
	if (confirm("是否保存设置的角色权限信息？")) {
		saveRolePermission(before_value, false);
	}
	
	before_value=$('#system_code').val();
	reloadTree($('#role_id').val(), $('#system_code').val());
}

function saveRolePermission(system_code, close) {
	var tmp = zTree1.getCheckedNodes();
	var value = '';
	if (tmp.length > 0) {
		for (var i = 0; i < tmp.length; i++) {
			value += ('{id:\"' + tmp[i].id + '\",type:\"'+tmp[i].type+'\"}');
			if (i < tmp.length - 1) {
				value += ',';
			}
		}
	}
	$.ajax({
		url: '../role/saveRolePermission.action',   
		type:'POST',
		dataType: 'html',
		data:{'system.system_code':system_code,'role.role_id':$('#role_id').val(),'roleString':('['+value+']')},
		beforeSend:function(xmlhttprequest){
		},
		success:function(data){
			if(close == true) {
				window.close();
			}
		},
		error:function(action, errortype, desc){
			alert("角色权限信息保存失败！");
		}
	});
}
